Skip to main content

Photo Interrupter Sensor

1. Write standard firmata to the device

Uploading Standard Firmata to Arduino Open Arduino IDE. File > Examples > Firmata > StandardFirmata.

Tools > Board > your board Tools > Serial Port > your port Click Upload button. if you use WSL, you need to follow this

2. Run the PhotoInterrupt sensor

index.tsx
import { Board, Led, PhotoInterrupter, render} from "edison"
import React, {useState} from "react"

const App: React.FC = () => {
const [isOn, setIsOn] = useState(false)

return (
<Board port={'/dev/tty***'} baudRate={57600}>
<PhotoInterrupter
pin={8}
triggered={() => {
setIsOn(true)
}}
untriggered={() => {
setIsOn(false)
}}
>
<Led
pin={13}
isOn={isOn}
/>
</PhotoInterrupter>
</Board>
)
}
render(<App />)

This program will blink the LED when the photo interrupter sensor is run.

3. execute the program

$ npx vite-node index.tsx 

You can use <PhotoInterrupter >

PropsTypeDescriptionDefault
pinnumberPin number to control currentNone
triggered?(() => void)Pin number to control currentNone
untriggered?(() => void)Pin number to control currentNone
childrenReact.ReactNodeChild components such as outbutNone